const captcha = require('trek-captcha');
const sessionFilter = require('../../../middlewares/clientSessionMiddleware');
const log4js = require('../../../utils/log4js');

const char = module.exports;

// 生成图形验证码
char.get_create =  async (req, res) => {
    const {token, buffer} = await captcha();
    req.session.captcha = token;

    res.setHeader('Content-Type', 'image/png');
    res.end(buffer);
};

// 验证图形验证码
char.get_check =  (req, res) => {
    let {captcha} = req.query;

    console.log(req.session.captcha);
    console.log(captcha);
    if(captcha === req.session.captcha) {
        res.jsonWrap(null,0,'正确')
    } else {
        res.jsonWrap(null,1,'验证码错误')
    }
};



